﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
        
           

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var uid = textBox1.Text.Trim();
            var pwd = textBox2.Text.Trim();
            var pwd1 = textBox3.Text.Trim();
            var str = string.Format("select Username from Users where Username='{0}'",uid );
            SqlConnection sqlConnection = new SqlConnection("server=.;database=Blogs;uid=sa;pwd=1361162012a");
            sqlConnection.Open();
            SqlCommand sqlCommand = new SqlCommand(str, sqlConnection);
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            sqlDataReader.Read();
            
            if (sqlDataReader.HasRows)
            {
                MessageBox.Show("该用户已被注册");
                
            }
          
            
            else
            {

                if (pwd == pwd1)
                {
                    var insert = string.Format("insert into Users(Username,Password) values ('{0}',{1})", uid, pwd);
                    var ins = DbHelp.dataSet(insert);
                    MessageBox.Show("注册成功");
                    Form3 form3 = new Form3();
                    this.Close();
                    
                }

                else
                {
                    MessageBox.Show("注册失败,两次密码不相同");
                }
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
